﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;

namespace P2PTransmit.ViewModal.Command
{
    public class FolderPicker:ICommandBase
    {
        P2PTransmitViewModal oj;
        Setting setting;
        public FolderPicker(P2PTransmitViewModal vm,Setting s)
        {
            oj = vm;
            setting = s;
        }

        public override bool CanExecute(object parameter)
        {
            return parameter is string;
        }

        public override void Execute(object parameter)
        {
            if(parameter is string)
            {
                var folder = new FolderBrowserDialog();
                if(folder.ShowDialog() == DialogResult.OK)
                {
                    if ( parameter.ToString() == "ErrorPath" )
                    {
                        oj.ErrorPath = folder.SelectedPath;
                        
                    }
                    if ( parameter.ToString() == "SavePath" )
                    {
                        oj.SavePath = folder.SelectedPath;

                    }
                    setting.Save();
                }
            }
        }
    }
}
